package com.erhya.export.poi.chain;

/**
 * 导出链
 */
public class ExcelExecuteChain {

    /** 文件名 */
    private String fileName;
    /** 头节点 */
    private ExcelChina head;
    /** 下一节点 */
    private ExcelChina next;

    public ExcelExecuteChain(String fileName) {
        this.fileName = fileName;
    }

    /**
     * 添加链条
     * @param excelChain 链条对象
     */
    public void addChain(ExcelChina excelChain){

        excelChain.setSuccessor(null);

        // 首次设置头节点
        if (head == null){
            this.head = excelChain;
            this.next = excelChain;
            return;
        }

        this.next.setSuccessor(excelChain);
        this.next = excelChain;
    }

    /**
     * 执行链条
     */
    public void executeChain(){
        if (this.head != null){
            try {
                this.head.execute(fileName);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
